package com.zhaopin.gitlab;

import com.zhaopin.utils.FileUtil;
import com.zhaopin.utils.GitUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.*;

@Slf4j
public class CheckAndGetNeedDownExt {


    //职位推荐名称
//    static String projectName = "project";
    //职位搜索名称
    static String projectName = "position";
    static String outputDir = projectName.equals("project") ? "dir/gitlab/recommend" : "dir/gitlab/position";
    static String RPOJECT_NAME_FILE = "/Users/zhaopin/IdeaProjects/easyjar/" + "dir/gitlab/" + projectName + "/position_need_update_file.txt";

    public static void main(String[] args) throws IOException {

        List<String> fileList = FileUtils.readLines(new File(RPOJECT_NAME_FILE), Charset.defaultCharset());

        //  /Users/zhaopin/IdeaProjects/position/config-position_search-live_campus_list-default-c_campus_r_h_live_livingtop_1110/project/src/main/java/function/concatTermWeight.groovy:JD_TITLE_TERMS_WEIGHT,

        for (String line : fileList) {

            String s = line.split(":")[0];
            String cellFileName = s.substring(s.lastIndexOf("/") + 1, s.lastIndexOf("."));
            String projectName = s.split("/")[5];
            String fileNames = line.split(":")[1];

            //下面拼接main文件的实际路径
            // /Users/zhaopin/IdeaProjects/position/config-position_search-position_campus_query-COMPANY-c_campus_outlink_filter_v1/project/src/main/java/config/main.groovy:SOU_CONTENT,SOU_POSITION_NAME,SOU_POSITION_NAME_QUERY,
            String mainGroovyFileName = "/Users/zhaopin/IdeaProjects/position/" + projectName + "/project/src/main/java/config/main.groovy";
            if(!"main".equals(cellFileName)){
                //读文件内容
                String mainGroovyConent = FileUtils.readFileToString(new File(mainGroovyFileName), Charset.defaultCharset());
                if (mainGroovyConent.contains(cellFileName)) {
                    //写文件
                    FileUtils.write(new File("/Users/zhaopin/IdeaProjects/easyjar/" + "dir/gitlab/position/position_not_down_file.txt"), projectName + ":" + cellFileName, Charset.defaultCharset(), true);
                    FileUtils.write(new File("/Users/zhaopin/IdeaProjects/easyjar/" + "dir/gitlab/position/position_not_down_file.txt"), "\r\n", Charset.defaultCharset(), true);
                } else {
                    FileUtils.write(new File("/Users/zhaopin/IdeaProjects/easyjar/" + "dir/gitlab/position/position_down_file.txt"), projectName + ":" + cellFileName + ":" + fileNames, Charset.defaultCharset(), true);
                    FileUtils.write(new File("/Users/zhaopin/IdeaProjects/easyjar/" + "dir/gitlab/position/position_down_file.txt"), "\r\n", Charset.defaultCharset(), true);
                }

            }


        }

    }


}
